package com.igeek.common.utils;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMailUtils {

	//发送给谁,发送的主题和内容 。
	public static void sendQQMail(String sendTo ,String subject ,String content) throws Exception {
		Properties prop = new Properties();
		prop.setProperty("mail.debug", "true");
		prop.setProperty("mail.host", "smtp.qq.com");
		prop.setProperty("mail.transport.protocol", "smtp");
		Session session = Session.getInstance(prop);
		Transport ts = session.getTransport();
		ts.connect("smtp.qq.com", "1547121883@qq.com", "eqztjfymelrqihha");
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress("1547121883@qq.com"));
		message.setRecipient(Message.RecipientType.TO, new InternetAddress(
				sendTo));
		message.setSubject(subject);
		message.setContent(content, "text/html;charset=UTF-8");
		ts.sendMessage(message, message.getAllRecipients());
		ts.close();
	}
	
	public static void send163Mail(String sendTo ,String subject ,String content) throws Exception {
		Properties prop = new Properties();
		prop.setProperty("mail.debug", "true");
		prop.setProperty("mail.host", "smtp.163.com");
		prop.setProperty("mail.transport.protocol", "smtp");
		Session session = Session.getInstance(prop);
		Transport ts = session.getTransport();
		ts.connect("smtp.163.com", "loveyh1557@163.com", "loveyh1557");
		//Message message = createSimpleMail(session);
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress("loveyh1557@163.com"));
		//Message.RecipientType.CC  抄送 。 TO 直接发送 。
		message.setRecipient(Message.RecipientType.TO, new InternetAddress(
				sendTo));//1473373048 梁康
		message.setSubject(subject);
		message.setContent(content, "text/html;charset=UTF-8");
		ts.sendMessage(message, message.getAllRecipients());
		ts.close();
	}
}
